
package com.mengmeizi.db;

import android.content.ContentValues;
import android.database.Cursor;

public class WallpaperDBBean {

    /** 表名。 */
    public static final String TABLE = "wallpaper_path";

    /** 图片位置 */
    public static final String LOCALPATH = "path";

    /** 图片序号 */
    public static final String INDEX = "_index";

    /** 图片url ，可以通过url获得图片缓存位置和下载地址 */
    public static final String IMAGEURL = "url";

    public String localPath;

    public String imageUrl;

    public int index;

    public static final String sql$createTable() {
        String sql = "create table if not exists " + TABLE//
                + " (" + INDEX + " INTEGER PRIMARY KEY,"//
                + LOCALPATH + " TEXT,"//
                + IMAGEURL + " TEXT"//
                + ");";
        return sql;
    }

    public static final String sql$dropTabel() {
        return "drop table if exists " + TABLE;
    }

    public ContentValues conver2ContentValues() {
        ContentValues cv = new ContentValues();
        cv.put(INDEX, index);
        cv.put(LOCALPATH, localPath);
        cv.put(IMAGEURL, imageUrl);
        return cv;
    }

    public static String sql$selectAll() {
        return "select * from " + TABLE;
    }

    public static String sql$selectObject(int index) {
        return "select * from " + TABLE + " where " + INDEX + "='" + index + "'";
    }

    public static String sql$delete(String arg) {
        return LOCALPATH + "='" + arg + "'";
    }

    public static WallpaperDBBean conver2Datas(Cursor cursor) {
        WallpaperDBBean bean = new WallpaperDBBean();
        bean.imageUrl = cursor.getString(cursor.getColumnIndex(IMAGEURL));
        bean.localPath = cursor.getString(cursor.getColumnIndex(LOCALPATH));
        return bean;
    }

    @Override
    public String toString() {
        return "localPath-->" + localPath + "----imageUrl-->" + imageUrl;
    }
}
